package com.company.Tree;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}21:27
 */
public class AVLTree {
    static class Node implements Comparable<Node>{
        int value;
        Node left;//左子结点
        Node right;

        public Node(int value) {
            this.value = value;
        }

        public void preOrder(){
            System.out.println(this);
            if (this.left!=null){
                this.left.preOrder();
            }
            if (this.right!=null){
                this.right.preOrder();
            }
        }

        //返回左子树的高度
        public int leftHeight(){
            if (left == null){
                return 0;
            }
            return left.height();
        }

        //返回右子树的高度
        public int rightHeight(){
            if (right == null){
                return 0;
            }
            return right.height();
        }

        //返回当前节点的高度，以该节点为根节点的树的高度
        public int height(){
            return Math.max(left == null ? 0 : left.height(),right == null ? 0 : right.height())+1;
        }

        @Override
        public String toString() {
            return "Node{" +
                    "value=" + value +
                    '}';
        }

        @Override
        public int compareTo(Node o) {
            return this.value-o.value;
        }
    }
}


